<?php
defined('_JEXEC') or die;

// disable core styles to avoid bs conflict
OC_Util::$core_styles = array();

if(isDevMode()) {
   OCP\Util::addStyle('jobposition', 'sheet.edit');
   OCP\Util::addScript('jobposition', 'sheet.edit');
} else {
   OCP\Util::addStyle('static', 'sheet.edit');
   OCP\Util::addScript('static', 'apps/jobpos.sheet.edit.min');
}
OCP\App::setActiveNavigationEntry('jobpos_index');

$job_detail = $_['job_detail'];
$jobsheet_detail = $_['jobsheet_detail'];
$sheet_detail = $_['sheet_detail'];
$questions = $_['questions'];
$ques_key = array('0'=>'A','1'=>'B','2'=>'C','3'=>'D','4'=>'E');
?>
<script type="text/javascript" src="<?php print_unescaped(OC_Helper::linkTo('jobposition/js', 'jobposition.php'));?>"></script>

<div class="hr_inner_navigate clearfix">
   <div class="hr_breadcrumbs">当前位置：<a href="<?php echo OCP\Util::linkToRoute("jobpos_index");?>">职位管理</a> &gt; <?=$job_detail->job_title?></div>
</div>

<div class="hr_addpaperbox">
   <div class="adp_setaction_box">
      <div class="adp_setaction clearfix">
         <?php if (!empty($sheet_detail)) : ?>
         <div class="adp_rightname yahei large pull-left">
            <span id="sheet_title"><?php echo $sheet_detail->title ? $sheet_detail->title : ""?></span>
            <span id="sheet_totaltime">（<?php echo $sheet_detail->totaltime ? $sheet_detail->totaltime : ""?>分钟）</span>
            <a id="edit_sheet" href="javascript:;" data="{sheet_id:'<?=$sheet_detail->id?>',title:'<?=addslashes($sheet_detail->title)?>',totaltime:'<?=$sheet_detail->totaltime?>'}">修改</a>
            <em>|</em>
            <a href="<?=OC_Helper::linkToRoute("jobpos_previewsheet",array('id'=>$sheet_detail->id,'jobid'=>$job_detail->id))?>" target="_blank">预览</a>
         </div>
         <?php endif;?>
         <form action="<?php echo OC_Helper::linkToRoute("jobpos_savesheet");?>" method="post" name="addsheetform" id="addsheetform" style="<?php echo !empty($sheet_detail) ? 'display:none' : ''?>">
            <div class="adp_setname pull-left">
               <label class="yahei large">试卷名称：</label>
               <input type="text" name="title" id="title" class="input-large" placeholder="请输入5~20个字符" value=""/>
            </div>
            <div class="adp_setname pull-left" style="margin-left:20px;">
               <label class="yahei large">答题时长：</label>
               <input type="text" name="totaltime" class="input-small" value=""/><span>分钟</span>
            </div>
            <button id="submit_button" class="ppp_bluebtn pull-left medium">保存</button>
            <span id='errormsg' class='error' style='color:red; display:none;'></span>
            <input type="hidden" name="job_id" value="<?=$job_detail->id?>"/>
            <input type="hidden" name="sheet_id" value="0"/>
            <input type="hidden" name="requesttoken" value="<?php echo $_['requesttoken'] ?>" id="requesttoken">
         </form>
         <a href="<?=OC_Helper::linkToRoute("jobpos_setup",array('id'=>$job_detail->id,'job_title'=>$job_detail->job_title))?>#onlinetest" class="pull-right">返回&gt;&gt;</a>

      </div>
   </div>

   <div class="adp_setpaper">
   <?php if(!empty($sheet_detail)):?>
      <?php if ($sheet_detail->hits == 0) : ?>
      <div class="adp_borderbox">
         <div class="positionaddtitle"><b>添加题目</b></div>
         <div class="form-horizontal adp-form-horizontal">
            <form action="<?php echo OC_Helper::linkToRoute("jobpos_savequestion");?>" method="post" name="addquestionform" id="addquestionform" >
            <div class="control-group">
               <label class="control-label">
                  <em class="redstar">*</em> 类型：
               </label>
               <div class="controls">
                  <label class="radio inline">
                     <input type="radio" name="typeid" class="required" id="singleanswer_radio" value="1"/>客观题
                  </label>
                  <label class="radio inline" id="last_typeid">
                     <input type="radio" name="typeid" class="required" id="freeinput_radio" value="3"/>主观题
                  </label>
               </div>
            </div>
            <div class="control-group">
               <label class="control-label">
                  <em class="redstar">*</em> 分值：
               </label>
               <div class="controls">
                  <input name="score" type="text" class="input-medium required digits">
               </div>
            </div>
            <div class="control-group">
               <label class="control-label">
                  <em class="redstar">*</em> 题目：
               </label>
               <div class="controls">
                  <textarea name="question" class="required" style="width:500px; height:100px;"></textarea>
               </div>
            </div>
            <div id="freeinput_div" class="control-group" style="display:none;">
               <label class="control-label">参考答案：</label>
               <div class="controls">
                  <textarea name="answer" style="width:500px; height:100px;"></textarea>
               </div>
            </div>
            <div id="singleanswer_div" class="control-group">
               <label class="control-label">
                  <em class="redstar">*</em> 选项：
               </label>
               <div class="controls">
                  <div class="adpeachanswer">
                     <input type="text" name="singleanswer[]" style="width:400px;">
                     <span class="adppostion_text">A</span>
                     <label class="radio inline">
                        <input type="radio" name="correctanswer" class="{required:true,messages:{required:'请选择正确答案！'}}" value="0"/><span class="graycolor">正确答案</span>
                     </label>
                  </div>
                  <div class="adpeachanswer">
                     <input type="text" name="singleanswer[]" style="width:400px;">
                     <span class="adppostion_text">B</span>
                     <label class="radio inline">
                        <input type="radio" name="correctanswer" value="1"/><span class="graycolor">正确答案</span>
                     </label>
                  </div>
                  <div class="adpeachanswer">
                     <input type="text" name="singleanswer[]" style="width:400px;">
                     <span class="adppostion_text">C</span>
                     <label class="radio inline">
                        <input type="radio" name="correctanswer" value="2"/><span class="graycolor">正确答案</span>
                     </label>
                  </div>
                  <div class="adpeachanswer">
                     <input type="text" name="singleanswer[]" style="width:400px;">
                     <span class="adppostion_text">D</span>
                     <label class="radio inline">
                        <input type="radio" name="correctanswer" value="3"/><span class="graycolor">正确答案</span>
                     </label>
                  </div>
                  <div class="adpeachanswer" id="last_choice">
                     <input type="text" name="singleanswer[]" style="width:400px;">
                     <span class="adppostion_text">E</span>
                     <label class="radio inline">
                        <input type="radio" name="correctanswer" value="4"/><span class="graycolor">正确答案</span>
                     </label>
                  </div>
               </div>
            </div>
            <div class="control-group">
               <div class="controls">
                 <button class="ppp_whitebtn btn">保存题目</button>
                 <span id='errormsg' class='error' style='color:red;display:none;'></span>
               </div>
            </div>
         <input type="hidden" name="job_id" value="<?=$job_detail->id?>"/>
         <input type="hidden" name="sheet_id" value="<?=$sheet_detail->id?>"/>
         <input type="hidden" name="question_id" value="0"/>
         <input type="hidden" name="requesttoken" value="<?php echo $_['requesttoken'] ?>" id="requesttoken">
         </form>
         </div>
      </div>
      <?php else:?>
      <div class="adp_yellowtip medium">试卷已使用过，不可修改题目分值、增删题目。</div>
      <?php endif;?>
   <?php else: ?>
   <div class="adp_mengban"><img src="/images/3/cannot_click.png"/></div>
   <?php endif;?>

   <?php if (!empty($questions)) : ?>
   <div id="questions_div">
      <?php foreach ($questions as $k => $q) : ?>
      <div class="each_ques_block" data="{qid:'<?=$q->questionid?>',job_id:'<?=$job_detail->id?>',sheet_id:'<?=$q->sheetid?>'}">
         <div id="each_ques_info_<?=$q->questionid?>" class="adp_borderbox adp_borderbox_blurbg eachquestion">
            <div class="adp_collapseastatus clearfix">
               <span>[<?=$q->typename?>]</span>
               <a href="javascript:;" class="papertesttitle"><?=$q->question?></a>
               <em>(<?=$q->score?>分)</em>
               <?php if ($sheet_detail->hits == 0) : ?>
               <a href="javascript:;" class="papertestdelete pull-right"></a>
               <?php endif;?>
               <a href="javascript:;" class="papertestedit pull-right"></a>
            </div>
         </div>
      <!-- Hidden each question action form -->
      <form action="<?php echo OC_Helper::linkToRoute("jobpos_savequestion");?>" method="post" name="each_ques_form_<?=$q->questionid?>" id="each_ques_form_<?=$q->questionid?>" style="display:none;" class="each_ques_form">
      <div class="adp_borderbox adp_borderbox_blurbg">
         <div class="form-horizontal adp-form-horizontal">
            <?php if ($sheet_detail->hits !== 0) : ?>
            <div class="control-group">
               <label class="control-label"><em class="redstar">*</em> 分值：</label>
               <div class="controls">
                  <input name="score" type="text" class="input-medium required digits" value="<?=$q->score?>">
               </div>
            </div>
            <?php else: ?>
            <div class="control-group">
               <label class="control-label"> 分值：</label>
               <div class="controls">
                  <span><?=$q->score?>分</span>&nbsp;<span class="adp_yellowtip">该题已有应聘者做过, 不可修改题目分值</span>
               </div>
            </div>
            <input name="score" type="hidden" value="<?=$q->score?>">
            <?php endif;?>
            <div class="control-group">
               <label class="control-label"><em class="redstar">*</em> 题目：</label>
               <div class="controls">
                  <textarea name="question" class="required" style="width:500px; height:100px;"><?=$q->question?></textarea>
               </div>
            </div>
            <?php if ($q->type == 'freeinput') : ?>
            <div class="control-group">
               <label class="control-label">参考答案：</label>
               <div class="controls">
                  <textarea name="answer" style="width:500px; height:100px;"><?php echo !empty($q->answer) ? trim($q->answer[0]) : '';?></textarea>
               </div>
            </div>
            <?php elseif ($q->type == 'singleanswer') :?>
            <div class="control-group">
               <label class="control-label"><em class="redstar">*</em> 选项：</label>
               <div class="controls">
                  <?php for ($i=0; $i < 5; $i++) { ?>
                     <div class="adpeachanswer">
                     <input type="text" name="singleanswer[]" value="<?php echo !empty($q->answer[$i]) ? $q->answer[$i]->choice : '';?>" style="width:400px;" class="<?php echo (!empty($q->answer[$i]) && $q->answer[$i]->answer == 1) ? "must_fill" : ''?>">
                     <span class="adppostion_text"><?=$ques_key[$i]?></span>
                     <label class="radio inline">
                        <input type="radio" name="correctanswer" class="{required:true,messages:{required:'请选择正确答案！'}}" value="<?=$i?>" <?php echo (!empty($q->answer[$i]) && $q->answer[$i]->answer == 1) ? "checked='checked'" : ''?>/>
                        <span class="graycolor">正确答案</span>
                     </label>
                  </div>
                  <?php }?>
               </div>
            </div>
            <?php endif;?>
            <div class="control-group">
               <div class="controls">
                  <button class="ppp_whitebtn btn submit_btn" disabled="disabled">保存题目</button>
                  <a href="javascript:;" class="medium adpresetbtn">取消</a>
                  <span id='errormsg' class='error' style='color:red;display:none;'></span>
                  <input type="hidden" name="typeid" value="<?=$q->typeid?>"/>
                  <input type="hidden" name="job_id" value="<?=$job_detail->id?>"/>
                  <input type="hidden" name="sheet_id" value="<?=$sheet_detail->id?>"/>
                  <input type="hidden" name="question_id" value="<?=$q->questionid?>"/>
                  <input type="hidden" name="requesttoken" value="<?php echo $_['requesttoken'] ?>" id="requesttoken">
               </div>
            </div>
         </div>
      </div>
      </form>
      </div>

      <?php endforeach;?>
   </div>
   <?php else: ?>
   <div id="questions_div"></div>
   <?php endif;?>

   </div>
</div>
